home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / clang / vecpro11.zip / VECPRO.H < prev    next >
Text File  |  1994-10-11  |  16KB  |  258 lines

  1. //
  2. //    VECPRO.H    Vector Pro Header File
  3. //
  4. //    Copyright 1994 by Vector Numerics, Inc.
  5. //
  6.  
  7. #include "math.h"
  8. #include "float.h"
  9. #include "stdlib.h"
  10. #include "errno.h"
  11.  
  12. #ifndef _VECTOR_PRO_DEFINED
  13. #define _VECTOR_PRO_DEFINED         /* avoid multiple def's  */
  14.  
  15. struct tenbytes
  16.     {
  17.     double r;
  18.     short s;
  19.     };
  20.  
  21. #ifndef    POLYNOMIAL_MAX_ORDER
  22. #define POLYNOMIAL_MAX_ORDER    20
  23. #endif
  24.  
  25. extern short vp_poly_max_order;
  26. extern double vp_pi;
  27.  
  28. struct poly
  29.     {
  30.     short order;
  31.     char waste[6]; // To force efficient data alignment in memory.
  32.     double co[POLYNOMIAL_MAX_ORDER + 1];
  33.     };
  34.  
  35. struct polyx
  36.     {
  37.     short order;
  38.     char waste[6]; // To force efficient data alignment in memory.
  39.     struct complex co[POLYNOMIAL_MAX_ORDER + 1];
  40.     };
  41.  
  42. // Error Return Codes:
  43. //
  44. #define        VP_DIV_BY_0        1
  45. #define        VP_INFINITY        2
  46. #define        VP_OVERFLOW        3
  47. #define        VP_UNDERFLOW        4
  48. #define        VP_SINGULAR        5
  49. #define        VP_OUT_OF_RANGE        6
  50. #define        VP_PARAM_ERROR        7
  51. #define        VP_ILL_CONDITIONED    8
  52. #define        VP_COMPLEX_RESULT    9
  53. #define        VP_INTERNAL_ERROR    10
  54. #define        VP_NO_CONVERGENCE    11
  55. #define        VP_ACC_PLOSS        12
  56. #define        VP_ACC_TLOSS        13
  57. #define        VP_DUPLICATES        14
  58. #define        VP_UNSORTED        15
  59. #define        VP_EXTRAPOLATED        16
  60.  
  61.  
  62. short    vecinit(short poly_max_order);
  63. short    sincos(double theta, double * s, double * c);
  64. short     cpx_add(struct complex * r, struct complex * a, struct complex * b);
  65. short     cpx_sub(struct complex * r, struct complex * a, struct complex * b);
  66. short     cpx_mult(struct complex * r, struct complex * a, struct complex * b);
  67. short     cpx_div(struct complex * r, struct complex * a, struct complex * b);
  68. short    cpx_abs(double * a, struct complex * c);
  69. short    cpx_arg(double * a, struct complex * c);
  70. short    cpx_convert(struct complex * c, double abs, double arg);
  71. short     cpx_sqrt(struct complex * r, struct complex * a);
  72. short     cpx_power(struct complex * r, struct complex * a, double exp);
  73. short     cpx_cpx_power(struct complex * r, struct complex * a, struct complex * exp);
  74. short    cpx_exp(struct complex * r, struct complex * a);
  75. short     cpx_ln(struct complex * r, struct complex * a);
  76. short     cpx_sin(struct complex * r, struct complex * a);
  77. short     cpx_cos(struct complex * r, struct complex * a);
  78. short    poly_zero(struct poly * r);
  79. short    poly_copy(struct poly * r, struct poly * a);
  80. short     poly_eval(double * r, double x, struct poly * a);
  81. short     poly_add(struct poly * r, struct poly * a, struct poly * b);
  82. short     poly_sub(struct poly * r, struct poly * a, struct poly * b);
  83. short     poly_mult(struct poly * r, struct poly * a, struct poly * b);
  84. short     poly_div(struct poly * r, struct poly * a, struct poly * b, struct poly * m);
  85. short     poly_lin_change(struct poly * r, struct poly * a, double ycoeff, double c, double * temp1, double * temp2);
  86. short     poly_deriv(struct poly * r, struct poly * a);
  87. short     poly_integ(struct poly * r, struct poly * a);
  88. short     poly_cpx_convert(struct polyx * r, struct poly * a);
  89. short    poly_cpx_zero(struct polyx * r);
  90. short    poly_cpx_copy(struct polyx * r, struct polyx * a);
  91. short     poly_cpx_eval(struct complex * r, struct complex * x, struct polyx * a);
  92. short     poly_cpx_add(struct polyx * r, struct polyx * a, struct polyx * b);
  93. short     poly_cpx_sub(struct polyx * r, struct polyx * a, struct polyx * b);
  94. short     poly_cpx_mult(struct polyx * r, struct polyx * a, struct polyx * b);
  95. short     poly_cpx_div(struct polyx * r, struct polyx * a, struct polyx * b, struct polyx * m);
  96. short     poly_cpx_lin_change(struct polyx * r, struct polyx * a, struct complex * ycoeff, struct complex * c, 
  97.                 struct complex * temp1, struct complex * temp2);
  98. short     poly_cpx_deriv(struct polyx * r, struct polyx * a);
  99. short     poly_cpx_integ(struct polyx * r, struct polyx * a);
  100. short     poly_cpx_root(struct complex * r, double * c, struct polyx * a, struct complex * guess);
  101. short     poly_cpx_roots(struct complex * r, double * c, struct polyx * a, struct polyx * tmp, struct polyx * tmp2, struct polyx * tmp3);
  102. short    vec_zero(double * r, short n);
  103. short     vec_copy(double * r, double * a, short n);
  104. short     vec_add(double * r, double * a, double * b, short na);
  105. short     vec_sub(double * r, double * a, double * b, short na);
  106. short     vec_scalar(double * r, double * a, double x, short na);
  107. short     vec_unit(double * r, double * a, short na);
  108. short     vec_dotprod(double * r, double * a, double * b, short nab);
  109. short     vec_crossprod(double * r, double * a, double * b);
  110. short    vec_total(double * r, short n, short n_inputs, double * a, double afactor, ...);
  111. short    vec_angle(double * r, double * a, double * b, short n);
  112. short    vec_magnitude(double * r, double * a, short n);
  113. short    vec_gendotprod(double * r, char * a, char * b, short na, short a_inc, short b_inc);
  114. short    mat_zero(double * r, short nr, short nc);
  115. short    mat_copy(double * r, double * a, short nr, short nc);
  116. short    mat_ident(double * r, short n);
  117. short    mat_add(double * r, double * a, double * b, short nr, short nc);
  118. short    mat_sub(double * r, double * a, double * b, short nr, short nc);
  119. short    mat_scalar(double * r, double * a, double x, short nr, short nc);
  120. short    mat_mult(double * r, double * a, double * b, short arows, short acols, short bcols);
  121. short    mat_trace(double * t, double * r, short n);
  122. short    mat_transpose(double * r, short nr, short nc, double * a);
  123. short    mat_lud(double * r, short n, short * row_pivots, short * dsign, double * temp, struct tenbytes * temp2);
  124. short    mat_determinant(double * r, short n, short * row_pivots, double * d, short dsign);
  125. short    mat_inverse(double * r, double * a, short n, short * row_pivots, double * tmp1, double * tmp2);
  126. short mat_inverse_errest(double * r, double * orig_a, double * a, short n, short * row_pivots, double * resid, double * err,
  127.              double * tmp1, double * tmp2, double * tmp3, double * tmp4);
  128. short    mat_solve(double * a, short n, short * row_pivots, double * x, double * b);
  129. short mat_errest(double * orig_a, double * a, short n, short * row_pivots, double * x, double * b, double * resid, double * err,
  130.                  double * tmp1, double * tmp2);
  131. short    mat_colop(double * r, short nr, short nc, short change_col, double x, short from_col);
  132. short    mat_rowop(double * r, short nr, short nc, short change_row, double x, short from_row);
  133. short    mat_zero_p(double * r, short nr, short nc, short rsiz_c);
  134. short    mat_copy_p(double * r, double * a, short nr, short nc, short rsiz_c, short asiz_c);
  135. short    mat_ident_p(double * r, short n, short rsiz_c);
  136. short    mat_add_p(double * r, double * a, double * b, short nr, short nc, short rsiz_c, short asiz_c, short bsiz_c);
  137. short    mat_sub_p(double * r, double * a, double * b, short nr, short nc, short rsiz_c, short asiz_c, short bsiz_c);
  138. short    mat_scalar_p(double * r, double * a, double x, short nr, short nc, short rsiz_c, short asiz_c);
  139. short    mat_mult_p(double * r, double * a, double * b, short arows, short acols, short bcols, short rsiz_c, short asiz_c, short bsiz_c);
  140. short    mat_trace_p(double * t, double * r, short n, short rsiz_c);
  141. short    mat_transpose_p(double * r, short nr, short nc, double * a, short rsiz_c, short asiz_c);
  142. short    mat_lud_p(double * r, short n, short * row_pivots, short * dsign, double * temp, struct tenbytes * temp2, short rsiz_c);
  143. short    mat_determinant_p(double * r, short n, short * row_pivots, double * d, short dsign, short rsiz_c);
  144. short    mat_inverse_p(double * r, double * a, short n, short * row_pivots, double * tmp1, double * tmp2, short rsiz_c, short asiz_c);
  145. short mat_inverse_errest_p(double * r, double * orig_a, double * a, short n, short * row_pivots, double * resid, double * err,
  146.                double * tmp1, double * tmp2, double * tmp3, double * tmp4,
  147.                short rsiz_c, short orig_a_siz_c, short asiz_c);
  148. short    mat_solve_p(double * a, short n, short * row_pivots, double * x, double * b, short rsiz_c);
  149. short mat_errest_p(double * orig_a, double * a, short n, short * row_pivots, double * x, double * b, double * resid, double * err,
  150.                  double * tmp1, double * tmp2, short orig_a_siz_c, short asiz_c);
  151. short    mat_colop_p(double * r, short nr, short nc, short change_col, double x, short from_col, short rsiz_c);
  152. short    mat_rowop_p(double * r, short nr, short nc, short change_row, double x, short from_row, short rsiz_c);
  153. short    binary_search_i(double * x, short n, double xi);
  154. short    binary_search(double * x, short n, double xi);
  155. short    heap_sort(double * x, short n, double ** others, short n_others);
  156. short    cubic_spline(double * x, double * y, double * y2, double * temp, short n);
  157. short    cubic_spline_int(double * x, double * y, double * y2, short n, double xi, double * yi);
  158.  
  159. // Error recovery versions:
  160. short    sincos_e(double theta, double * s, double * c);
  161. short     cpx_add_e(struct complex * r, struct complex * a, struct complex * b);
  162. short     cpx_sub_e(struct complex * r, struct complex * a, struct complex * b);
  163. short     cpx_mult_e(struct complex * r, struct complex * a, struct complex * b);
  164. short     cpx_div_e(struct complex * r, struct complex * a, struct complex * b);
  165. short    cpx_abs_e(double * a, struct complex * c);
  166. short    cpx_argument_e(double * a, struct complex * c);
  167. short    cpx_convert_e(struct complex * c, double abs, double arg);
  168. short     cpx_sqrt_e(struct complex * r, struct complex * a);
  169. short     cpx_power_e(struct complex * r, struct complex * a, double exp);
  170. short     cpx_cpx_power_e(struct complex * r, struct complex * a, struct complex * exp);
  171. short    cpx_exp_e(struct complex * r, struct complex * a);
  172. short     cpx_ln_e(struct complex * r, struct complex * a);
  173. short     cpx_sin_e(struct complex * r, struct complex * a);
  174. short     cpx_cos_e(struct complex * r, struct complex * a);
  175. short    poly_zero_e(struct poly * r);
  176. short    poly_copy_e(struct poly * r, struct poly * a);
  177. short     poly_eval_e(double * r, double x, struct poly * a);
  178. short     poly_add_e(struct poly * r, struct poly * a, struct poly * b);
  179. short     poly_sub_e(struct poly * r, struct poly * a, struct poly * b);
  180. short     poly_mult_e(struct poly * r, struct poly * a, struct poly * b);
  181. short     poly_div_e(struct poly * r, struct poly * a, struct poly * b, struct poly * m);
  182. short     poly_lin_change_e(struct poly * r, struct poly * a, double ycoeff, double c, double * temp1, double * temp2);
  183. short     poly_deriv_e(struct poly * r, struct poly * a);
  184. short     poly_integ_e(struct poly * r, struct poly * a);
  185. short     poly_cpx_convert_e(struct polyx * r, struct poly * a);
  186. short    poly_cpx_zero_e(struct polyx * r);
  187. short    poly_cpx_copy_e(struct polyx * r, struct polyx * a);
  188. short     poly_cpx_eval_e(struct complex * r, struct complex * x, struct polyx * a);
  189. short     poly_cpx_add_e(struct polyx * r, struct polyx * a, struct polyx * b);
  190. short     poly_cpx_sub_e(struct polyx * r, struct polyx * a, struct polyx * b);
  191. short     poly_cpx_mult_e(struct polyx * r, struct polyx * a, struct polyx * b);
  192. short     poly_cpx_div_e(struct polyx * r, struct polyx * a, struct polyx * b, struct polyx * m);
  193. short     poly_cpx_lin_change_e(struct polyx * r, struct polyx * a, struct complex * ycoeff, struct complex * c, 
  194.                 struct complex * temp1, struct complex * temp2);
  195. short     poly_cpx_deriv_e(struct polyx * r, struct polyx * a);
  196. short     poly_cpx_integ_e(struct polyx * r, struct polyx * a);
  197. short     poly_cpx_root_e(struct complex * r, double * c, struct polyx * a, struct complex * guess);
  198. short     poly_cpx_roots_e(struct complex * r, double * c, struct polyx * a, struct polyx * tmp, struct polyx * tmp2, struct polyx * tmp3);
  199. short    vec_zero_e(double * r, short n);
  200. short     vec_copy_e(double * r, double * a, short n);
  201. short     vec_add_e(double * r, double * a, double * b, short na);
  202. short     vec_sub_e(double * r, double * a, double * b, short na);
  203. short     vec_scalar_e(double * r, double * a, double x, short na);
  204. short     vec_unit_e(double * r, double * a, short na);
  205. short     vec_dotprod_e(double * r, double * a, double * b, short nab);
  206. short     vec_crossprod_e(double * r, double * a, double * b);
  207. short    vec_total_e(double * r, short n, short n_inputs, double * a, double afactor, ...);
  208. short    vec_angle_e(double * r, double * a, double * b, short n);
  209. short    vec_magnitude_e(double * r, double * a, short n);
  210. short    vec_gendotprod_e(double * r, char * a, char * b, short na, short a_inc, short b_inc);
  211. short    mat_zero_e(double * r, short nr, short nc);
  212. short    mat_copy_e(double * r, double * a, short nr, short nc);
  213. short    mat_ident_e(double * r, short n);
  214. short    mat_add_e(double * r, double * a, double * b, short nr, short nc);
  215. short    mat_sub_e(double * r, double * a, double * b, short nr, short nc);
  216. short    mat_scalar_e(double * r, double * a, double x, short nr, short nc);
  217. short    mat_mult_e(double * r, double * a, double * b, short arows, short acols, short bcols);
  218. short    mat_trace_e(double * t, double * r, short n);
  219. short    mat_transpose_e(double * r, short nr, short nc, double * a);
  220. short    mat_lud_e(double * r, short n, short * row_pivots, short * dsign, double * temp, struct tenbytes * temp2);
  221. short    mat_determinant_e(double * r, short n, short * row_pivots, double * d, short dsign);
  222. short    mat_inverse_e(double * r, double * a, short n, short * row_pivots, double * tmp1, double * tmp2);
  223. short mat_inverse_errest_e(double * r, double * orig_a, double * a, short n, short * row_pivots, double * resid, double * err,
  224.              double * tmp1, double * tmp2, double * tmp3, double * tmp4);
  225. short    mat_solve_e(double * a, short n, short * row_pivots, double * x, double * b);
  226. short mat_errest_e(double * orig_a, double * a, short n, short * row_pivots, double * x, double * b, double * resid, double * err,
  227.                  double * tmp1, double * tmp2);
  228. short    mat_colop_e(double * r, short nr, short nc, short change_col, double x, short from_col);
  229. short    mat_rowop_e(double * r, short nr, short nc, short change_row, double x, short from_row);
  230. short    mat_zero_p_e(double * r, short nr, short nc, short rsiz_c);
  231. short    mat_copy_p_e(double * r, double * a, short nr, short nc, short rsiz_c, short asiz_c);
  232. short    mat_ident_p_e(double * r, short n, short rsiz_c);
  233. short    mat_add_p_e(double * r, double * a, double * b, short nr, short nc, short rsiz_c, short asiz_c, short bsiz_c);
  234. short    mat_sub_p_e(double * r, double * a, double * b, short nr, short nc, short rsiz_c, short asiz_c, short bsiz_c);
  235. short    mat_scalar_p_e(double * r, double * a, double x, short nr, short nc, short rsiz_c, short asiz_c);
  236. short    mat_mult_p_e(double * r, double * a, double * b, short arows, short acols, short bcols, short rsiz_c, short asiz_c, short bsiz_c);
  237. short    mat_trace_p_e(double * t, double * r, short n, short rsiz_c);
  238. short    mat_transpose_p_e(double * r, short nr, short nc, double * a, short rsiz_c, short asiz_c);
  239. short    mat_lud_p_e(double * r, short n, short * row_pivots, short * dsign, double * temp, struct tenbytes * temp2, short rsiz_c);
  240. short    mat_determinant_p_e(double * r, short n, short * row_pivots, double * d, short dsign, short rsiz_c);
  241. short    mat_inverse_p_e(double * r, double * a, short n, short * row_pivots, double * tmp1, double * tmp2, short rsiz_c, short asiz_c);
  242. short mat_inverse_errest_p_e(double * r, double * orig_a, double * a, short n, short * row_pivots, double * resid, double * err,
  243.                double * tmp1, double * tmp2, double * tmp3, double * tmp4,
  244.                short rsiz_c, short orig_a_siz_c, short asiz_c);
  245. short    mat_solve_p_e(double * a, short n, short * row_pivots, double * x, double * b, short rsiz_c);
  246. short mat_errest_p_e(double * orig_a, double * a, short n, short * row_pivots, double * x, double * b, double * resid, double * err,
  247.                  double * tmp1, double * tmp2, short orig_a_siz_c, short asiz_c);
  248. short    mat_colop_p_e(double * r, short nr, short nc, short change_col, double x, short from_col, short rsiz_c);
  249. short    mat_rowop_p_e(double * r, short nr, short nc, short change_row, double x, short from_row, short rsiz_c);
  250. short    binary_search_i_e(double * x, short n, double xi);
  251. short    binary_search_e(double * x, short n, double xi);
  252. short    heap_sort_e(double * x, short n, double ** others, short n_others);
  253. short    cubic_spline_e(double * x, double * y, double * y2, double * temp, short n);
  254. short    cubic_spline_int_e(double * x, double * y, double * y2, short n, double xi, double * yi);
  255.  
  256. #endif
  257.  
  258.